package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 查询评论列表
     * GET
     * movementId  page pagesize
     * 返回数据：  PageResult
     */
    @GetMapping
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String movementId) {
        PageResult vo = commentsService.findComments(page, pagesize, movementId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 发布评论
     * POST
     * Body参数：
     * movementId      comment
     * 返回数据 null
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map) {
        //获取请求参数
        String movementId = map.get("movementId").toString();
        String comment = map.get("comment").toString();
        //定义定义servic
        commentsService.saveComment(movementId,comment);
        return ResponseEntity.ok(null);
    }
}
